var lastValue = "", nodeList = [], fontCss = {};
var tloadinit;
ztreeLayerAsyncOpenCloseUtils = {
	openTreeNodesStrDefault : function(openUrl,postUrl,titles){
		var titles = title;//"给【"+rolename+"】分配权限";
		top.layer.open({
		  type: 2,
		  title: titles,
		  shade: 0.5,//背景色深度
		  fixed: false, //不固定
		  maxmin: true,
		  anim : 1,
		  shadeClose: false,//点击其它区域关闭
		  content:  openUrl,//'ztreeLayerAsyncAjaxPostUtilsLayer.do?rid='+id,
		  area: ['300px' , '650px'],
		  btn : ["提交",'关闭'],
		  yes : function(index,layero){
			  var body = top.layer.getChildFrame('body',index);
				var iframeWin = layero.find('iframe')[0];//得到iframe页的窗口对像，执行iframe页的方法，iframeWin.method();
				var values = iframeWin.contentWindow.ztreeLayerAsyncAjaxPostUtils.doSubmitTreeNodesStrPost(postUrl);
				if(values){
					var result = 0;
					var count = 0;
					var tmsg = top.layer.msg('数据提交中.......', {
						time : 100000,
						icon : 6
					});
					var tload = top.layer.load(0, {
						shade : [ 0.5, '#fff' ]
					}); // 0代表加载的风格，支持0-2
					ztreeLayerAsyncOpenCloseUtils.asyncSaveCallBackClose(iframeWin, index, result, 1000, count,tmsg, tload);
				}
		  },
		  end: function(index){
			  
		  }
		});
	},
	openTreeNodesStrByWH : function(openUrl,postUrl,titles,w,h){
		//var titles = "给【"+rolename+"】分配权限";
		top.layer.open({
		  type: 2,
		  title: titles,
		  shade: 0.5,//背景色深度
		  fixed: false, //不固定
		  maxmin: true,
		  anim : 1,
		  shadeClose: false,//点击其它区域关闭
		  content:  openUrl,//'ztreeLayerAsyncAjaxPostUtilsLayer.do?rid='+id,
		  area: [w+'px' , h+'px'],
		  btn : ["提交",'关闭'],
		  yes : function(index,layero){
			  var body = top.layer.getChildFrame('body',index);
				var iframeWin = layero.find('iframe')[0];//得到iframe页的窗口对像，执行iframe页的方法，iframeWin.method();
				var values = iframeWin.contentWindow.ztreeLayerAsyncAjaxPostUtils.doSubmitTreeNodesStrPost(postUrl);
				if(values){
					var result = 0;
					var count = 0;
					var tmsg = top.layer.msg('数据提交中.......', {
						time : 100000,
						icon : 6
					});
					var tload = top.layer.load(0, {
						shade : [ 0.5, '#fff' ]
					}); // 0代表加载的风格，支持0-2
					ztreeLayerAsyncOpenCloseUtils.asyncSaveCallBackClose(iframeWin, index, result, 1000, count,tmsg, tload);
				}
		  },
		  end: function(index){
			  
		  }
		});  
	},
	browseOpenDefault : function(openUrl,titles){
		//var titles = title;//"浏览角色【"+rolename+"】权限";
		top.layer.open({
		  type: 2,
		  title: titles,
		  shade: 0.5,//背景色深度
		  fixed: false, //不固定
		  maxmin: true,
		  anim : 1,
		  shadeClose: false,//点击其它区域关闭
		  content:  openUrl,//'ztreeLayerAsyncAjaxPostUtilsLayer.do?rid='+rid,
		  area: ['300px' , '650px'],
		  btn : ['关闭'],
		  end: function(index){
			  
		  }
		});  
	},
	browseOpenByWH : function(openUrl,titles,w,h){
		//var titles = title;//"浏览角色【"+rolename+"】权限";
		top.layer.open({
		  type: 2,
		  title: titles,
		  shade: 0.5,//背景色深度
		  fixed: false, //不固定
		  maxmin: true,
		  anim : 1,
		  shadeClose: false,//点击其它区域关闭
		  content:  openUrl,//'ztreeLayerAsyncAjaxPostUtilsLayer.do?rid='+rid,
		  area: [w+'px' , h+'px'],
		  btn : ['关闭'],
		  end: function(index){
			  
		  }
		});  
	},
	asyncSaveCallBackClose : function(iframeWin, index, result, time, count,tmsg, tload) {
		return setTimeout(function() {
			count++;
			result = iframeWin.contentWindow.ztreeLayerAsyncAjaxPostUtils.asyncTreeCallResult();
			if (result == 1) {
				top.layer.msg('数据提交成功.......', {
					time : 2000,
					icon : 6
				});
				top.layer.close(index);
				top.layer.close(tmsg);
				top.layer.close(tload);
			} else if(result == -1){
				if (count > 5) {
					top.layer.alert('数据提交失败....', {
						skin : 'layui-layer-lan',
						closeBtn : 0,
						anim : 4,
						icon : 5
					});
					top.layer.close(index);
					top.layer.close(tmsg);
					top.layer.close(tload);
				} else {
					ztreeLayerAsyncOpenCloseUtils.asyncSaveCallBackClose(iframeWin, index, result, (time + 1000), count,tmsg, tload);
				}
			}else if(result==-110){
				top.layer.close(tload);
				top.layer.alert('访问服务器接口出错....', {
					skin : 'layui-layer-lan',
					closeBtn : 0,
					anim : 4,
					icon : 5
				});
			}else{
				top.layer.close(tload);
				var error = iframeWin.contentWindow.ztreeLayerAsyncAjaxPostUtils.asyncTreeCallResultError();
				top.layer.alert('操作失败。错误码：'+result+" 错误信息："+error, {
					skin : 'layui-layer-lan',
					closeBtn : 0,
					anim : 4,
					icon : 5
				});
			}
		}, time);
	}
}
